#!/usr/bin/python
# -*- coding: UTF-8 -*-
################################################################################
#
# Copyright (c) 2020 openEuler.org, Inc. All Rights Reserved
#
################################################################################
"""
send email

Authors: xiaojianghui
Date:    11/06/2020 11:01 AM
"""

from dbConnecttion.MysqlConn import Mysql
from emailtask import sendemail
import os


def sending():
    """
        Query all recipients
    """
    mysql = Mysql()
    sql = "select email_name from cve_email_list where email_type=1"
    result = mysql.getMany(sql)
    mysql.close()
    print(result)
    for i in result:
        subject = "This time cve creates an issue record"
        content = "The email attachment may contain two attached excel documents, " \
                  "which are the issue data that has been successfully " \
                  "created and the issue data that has not been created."
        # sendemail.send_email("smtp.gmail.com", 587,
        #                      os.getenv("CVE_EMAIL_SENDADDR"),
        #                      os.getenv("CVE_EMAIL_PASSWORD"),
        #                      str(i['email_name']), './export_excels', subject, content)
        sendemail.send_email('mailman-exim4-service.mail.svc.cluster.local', 25,
                             os.getenv("CVE_EMAIL_SENDADDR"),
                             os.getenv("CVE_EMAIL_PASSWORD"),
                             str(i['email_name']), './export_excels', subject, content)
